<?php
/*===========================================================================
Koneksi, perintah query.....
===========================================================================*/
require_once('Connections/dodol.php'); 
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
	{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;}
}
mysql_select_db($database_dodol, $dodol);
?>

<?php
for($a=1;$a<=35;$a++){
$b=$a+1;
	for(;$b<=35;$b++){
$query_db = sprintf("SELECT status FROM status_1 WHERE matkul1 = %s AND matkul2 = %s", GetSQLValueString($a, "text"),GetSQLValueString($b, "text"));
$matkul_db = mysql_query($query_db, $dodol) or die(mysql_error());		//query
$row_db = mysql_fetch_assoc($matkul_db);								//dapetin barisnya
$bentrokan[$a][$b]=$row_db['status'];
}
}
?>

<?php
$db_status="status_1";
echo "<h1>PHP Worked</h1>";
echo "Adi_a12<br/><br/>";
//$a=makanan;
//include_once "123.php";
//echo $a;

include_once "test2.php";
//include_once "test3.php";

//echo "<br/><table border='1'>";
//for ($a=1;$a<=6;$a++)
//{
//echo "<tr><td>Individu-".$a."</td>";				//
	for ($b=1;$b<=20;$b++)
	{
		//echo "<td>";									//
		$ggg[$b]=$kromosom[$a][$b]= mt_rand(1,30);
		//echo $ggg[$b]."</td>";
		//echo $ggg[$b]."<br/>";		//
	}
quickCount2($ggg, $db_status);
//$fit_sum[$a]=quickCount($ggg);
//$fit_av=$fit_av + $fit_sum[$a];
//echo "<td>".$fit_sum[$a]."</td>";			//
//echo "</tr>";
//}
//echo "</table>";

function quickCount2($makan, $db_stat)
{
echo "<table border='1'>";
$unik = array_unique($makan);	//dapetin angka unik
$hitung = count($unik);			//hitung ada berapa angka unik
//echo "<tr>";
foreach ($unik as &$value) {	//rubah angka unik; array() => array[]
    $unik2[]=$value;
	echo "<td>".$value."</td>";
}unset($value);
echo "</tr><tr>";
$jumlah = array_count_values($makan);	//hitung banyaknya tiap angka unik
//print_r($jumlah);

foreach ($jumlah as &$value) {	//rubah banyaknya angka unik; array() => array[]
    $jumlah2[]=$value;
	echo "<td>".$value."</td>";
}unset($value);echo "</tr></table>";

//-----
$i=1;
foreach($jumlah as $key => $value){
if ($value>1){
$angkanya[$i]=$key;$jumlahnya[$i]=$value;
echo $key.":".$value."<br/>";$i++;}
}

/*echo "--------------<br/>";
$a=0;
foreach($angkanya as $value){
$i=0;$a++;$samanya[$a][$i]=$value;
echo $value;
	foreach($makan as $value2){
	$i++;
		if ($value==$value2){
		echo ":".$i;
		}
	}
echo "<br/>";
}*/

echo "--------------<br/>";$i=1;$a=0;
foreach($angkanya as $value){
$b=0;$c=1;
if($jumlahnya[$i]<3)
	{
	foreach($makan as $value2){
	$b++;
		if ($value==$value2){
			if($c==1){$matkul1=$b;echo ":[".$matkul1;}
			elseif ($c==2){$matkul2=$b;echo ":".$matkul2;}
		$c++;
		}
	}
	//echo "-".$matkul1 .":". $matkul2;
	//echo "-".$fit_bentrok[$i]=($bentrokan[$matkul1][$matkul2])*10;
	}
elseif($jumlahnya[$i]>2)
	{$fit_bentrok[$i]=20;
	}
echo "<br/>";$i++;
}
echo array_sum($fit_bentrok);
echo $bentrokan[1][2];
}
?>